package com.qyhl.module_practice.map;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeListBean;

import java.util.List;

public class PracticeMapModel implements PracticeMapContract.PracticeMapModel {
    private PracticeMapPresenter mPresenter;

    PracticeMapModel(PracticeMapPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String instId) {
        EasyHttp.get(PracticeUrl.GET_PRACTICE_STREET_MAP_LIST_NEW)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<PracticeListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何机构位置信息！");
                        } else {
                            mPresenter.setError("获取坐标，请重新尝试！");
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeListBean> practiceListBeans) {
                        if (practiceListBeans != null && practiceListBeans.size() > 0) {
                            mPresenter.setList(practiceListBeans);
                        } else {
                            mPresenter.setError("暂无任何机构位置信息！");
                        }
                    }
                });
    }
}
